VC2008编译运行异常freejapanxxxxhd是什么意思

您所在的位置:网站首页 run free是什么意思 VC2008编译运行异常freejapanxxxxhd是什么意思

VC2008编译运行异常freejapanxxxxhd是什么意思

2023-03-15 09:32| 来源: 网络整理| 查看: 265

开发过程中,有时候会遇到堆异常的情况 这时,VS的调试输出窗口会提示: HEAP[MemTest.exe]: HEAP: Free Heap block 39b998 modified at 39b9c0 after it was freed Windows has triggered a breakpoint in MemTest.exe.

This may be due to a corruption of the heap, which indicates a bug in MemTest.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while MemTest.exe has focus.

The output window may have more diagnostic information.

就是说已经释放的堆内存被修改了,一般就是new/malloc 后的内存,在被delete/free后又被使用了 一个简单例子

#include "stdafx.h" #include #include void test(void); void testStruct(void); void tt(void); struct tagTest { int a; int b; }; int _tmain(int argc, _TCHAR* argv[]) { testStruct(); test(); system("pause"); return 0; } void test(void) { char* pBuffer = new char[128]; strcpy(pBuffer, "hello"); printf("%p %s\n", pBuffer, pBuffer); delete[] pBuffer; strcpy(pBuffer, "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH"); printf("%p %s\n", pBuffer, pBuffer); tt(); } void tt(void) { printf("I do nothing\n"); } void testStruct(void) { tagTest* pTest = new tagTest(); pTest->a = 0x11111111; pTest->b = 0x22222222; printf("%p %d, %d\n", pTest, pTest->a, pTest->b); delete pTest; pTest->a = 0x33333333; pTest->b = 0x44444444; printf("%p %d, %d\n", pTest, pTest->a, pTest->b); tt(); }

 

VC2008编译运行以上程序(DEBUG模式),发现运行到void test(void)函数的new那条语句时程序报错 不过这个new是不应该报此错误的,顶多报个内存不足就够了……郁闷啊,后来发现,对内存被释放后再使用是不会立即报错的,等到再次使用堆操作函数时才会报错。 也就是说,当时的调用堆栈是不准确的,那定位真正出问题的地方才是关键。

Free Heap block AAAA modified at BBBB after it was freed在这句提示里,block AAAA 不是平时申请地址后的返回值,一般都比我们申请的小一些,在VC2008 DEBUG的模式下这个值比申请出来的小40(0x28)的字节, 地址 BBBB 应该总是不小于 AAAA。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3